package com.bruce.algorithm.leetcode.linklist;

/**
 * @author luotuan
 * @ URl https://leetcode-cn.com/problems/remove-linked-list-elements/submissions/
 * @Description 203. 移除链表元素
 * @create 2020-07-18 16:46
 **/
public class LinkListRemove {
    public ListNode removeElements(ListNode head, int val) {
        ListNode newHead = null;
        ListNode node = newHead;
        ListNode nowNode = null;
        while (head!=null){
            int value = head.val;
            if(value != val){
                nowNode = new ListNode(value);
                if(newHead==null){
                    newHead = nowNode;
                    node = newHead;
                }else{
                    node.next = nowNode;
                    node = node.next;
                }
            }
            head = head.next;
        }
        return newHead;
    }

    public static void main(String[] args) {

    }
}
